
function thisMovie(movieName)
{
    if (navigator.appName.indexOf("Microsoft") != -1)
        return window[movieName];
    else
        return document[movieName];
}
var t = 0;
function Auto()
{
    //ws.send('SPing:');
    socket.emit('message', 'SPing:');
}
function XHConn() {
    var xmlhttp;
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp = new XMLHttpRequest();
            } catch (e) {
                xmlhttp = false;
            }
        }
    }

    return xmlhttp;
}


function async(arg, callback) {
    // console.log('参数为 ' + arg +' , 1秒后返回结果');
    setTimeout(function(){callback(arg * 2);}, Math.random()*2000);
}

function interfaceInit()
{
//setInterval('Auto()',30000);
    POPChat = (function() {
        var list = [];
        var user = null;
        var win = null;
        return{
            Init: function() {


            },
            send: function() {
                if (user == null)
                    return;
                var toUserInfo = UserList.get(user.chatid);
				var msg = $("#layim_write").html().str_replace().replace("<br>", "");
                PutMessage(My.rid, My.chatid, user.chatid, My.nick, user.nick, 'true', '', msg, '');

                if (typeof (toUserInfo) == "undefined" || user.chatid.indexOf('x_r') > -1) {
                    POPChat.showmsg(My, user, msg);
                    win.find("#layim_write").html("");
                    MsgCAlert();
                    alert('用户离线,消息转存到历史纪录！');
                    return;
                }
                var str = 'SendMsg=M=' + user.chatid + '|true|color:#000|' + msg+'|' + My.qx;

                ws.send(str);

                win.find("#layim_write").html("");
                win.find("#layim_write").focus();
                MsgCAlert();
            },
            newtab: function(u) {
                var layim_chatmore = win.find('#layim_chatmore');
                var layim_chatarea = win.find('#layim_chatarea');

                if (win.find('#layim_user' + u.chatid).length < 1) {
                    layim_chatmore.find('ul>li').removeClass('layim_chatnow');
                    layim_chatmore.find('ul').append('<li data-qq="" data-id="' + u.chatid + '" data-nick="' + u.nick + '" id="layim_user' + u.chatid + '" class="layim_chatnow"><span><b class="layim_msgnum">0</b>' + u.nick + '</span><em  data-id="' + u.chatid + '">×</em></li>');
                    layim_chatarea.find('.layim_chatview').removeClass('layim_chatthis');
                    layim_chatarea.append('<ul class="layim_chatview layim_chatthis" id="layim_area' + u.chatid + '"></ul>');

                    $.ajax({type: 'GET', dataType: 'JSON', url: '../ajax.php?act=mymsgold&tuid=' + u.chatid,
                        success: function(data) {
							if(data == null) {
								return;
							}
                            $("#layim_area" + data.tuid).prepend(data.msg);
                            $("#layim_user" + data.tuid).attr('data-qq', data.realname);
                            win.find('.layim_qq').html("<span><a href='http://wpa.qq.com/msgrd?v=3&uin=" + data.realname + "&site=qq&menu=yes' target='_blank'><img src='./images/icon_qq.png' border=0>" + data.realname + "</a></span>");
                            if (data.realname != "" && data.realname != '0') {
                                win.find('.layim_names').css("line-height", '20px');
                                win.find('.layim_qq').show();
                            } else {
                                win.find('.layim_names').css("line-height", '40px');
                                win.find('.layim_qq').hide();
                            }

                            u = UserList.get(u.chatid);
                            if (u != undefined && data.kfmsg != "" && data.kfmsg != 'null' && data.kfmsg != undefined) {
                                var str = '<li class="layim_chatehe"><div class="layim_chatuser"><img src="../face/img.php?t=p1&u=' + u.chatid + '"><span class="layim_chatname">' + u.nick + '</span><span class="layim_chattime">' + Datetime(0) + '</span></div><div class="layim_chatsay"><font style="color:#000">' + data.kfmsg + '</font><em class="layim_zero"></em></div></li>';
                                $("#layim_area" + u.chatid).append(str);
                            }
                            win.find('#layim_area' + data.tuid).scrollTop(win.find('#layim_area' + data.tuid)[0].scrollHeight);
                        }});


                }


                win.show();
                if (layim_chatmore.find('li').length < 2) {

                    POPChat.showtab(u);
                }
            },
            showtab: function(u) {
                user = u;
                var layim_chatmore = win.find('#layim_chatmore');
                var layim_chatarea = win.find('#layim_chatarea');

                layim_chatmore.find('ul>li').removeClass('layim_chatnow');
                layim_chatarea.find('.layim_chatview').removeClass('layim_chatthis');

                win.find('#layim_user' + u.chatid).addClass('layim_chatnow');
                win.find('#layim_area' + u.chatid).addClass('layim_chatthis');


                win.find('.layim_chatnow .layim_msgnum').text("0");
                win.find('.layim_chatnow .layim_msgnum').hide();

                win.find('.layim_face>img').attr('src', '../face/img.php?t=p1&u=' + u.chatid);
                win.find('.layim_names').text(u.nick);

                win.show();
                win.find('#layim_area' + u.chatid).scrollTop(win.find('#layim_area' + u.chatid)[0].scrollHeight);

                win.find('.layim_qq').html("<span><a href='http://wpa.qq.com/msgrd?v=3&uin=" + $("#layim_user" + u.chatid).attr('data-qq') + "&site=qq&menu=yes'  target='_blank'><img src='./images/icon_qq.png' border=0>" + $("#layim_user" + u.chatid).attr('data-qq') + "</a>");

                if ($("#layim_user" + u.chatid).attr('data-qq') != "" && $("#layim_user" + u.chatid).attr('data-qq') != '0') {
                    win.find('.layim_names').css("line-height", '20px');
                    win.find('.layim_qq').show();
                } else {
                    win.find('.layim_names').css("line-height", '40px');
                    win.find('.layim_qq').hide();
                }
            },
            showmsg: function(u, u1, str) {
                if (user.chatid != u.chatid && u.chatid != My.chatid) {
                    win.find('#layim_user' + u.chatid + ' .layim_msgnum').show();
                    win.find('#layim_user' + u.chatid + ' .layim_msgnum').text(Number(win.find('#layim_user' + u.chatid + ' .layim_msgnum').text()) + 1 + "");
                }
                var log = {};
                if (u.chatid == My.chatid)
                    log.imarea = win.find('#layim_area' + u1.chatid);
                else
                    log.imarea = win.find('#layim_area' + u.chatid);
                log.html = function(param, type) {
                    return '<li class="' + (type === 'me' ? 'layim_chateme' : ' layim_chatehe') + '">'
                            + '<div class="layim_chatuser">'
                            + function() {
                                if (type === 'me') {
                                    return '<span class="layim_chattime">' + param.time + '</span>'
                                            + '<span class="layim_chatname">' + param.name + '</span>'
                                            + '<img src="' + param.face + '" >';
                                } else {
                                    return '<img src="' + param.face + '" >'
                                            + '<span class="layim_chatname">' + param.name + '</span>'
                                            + '<span class="layim_chattime">' + param.time + '</span>';
                                }
                            }()
                            + '</div>'
                            + '<div class="layim_chatsay">' + param.content + '<em class="layim_zero"></em></div>'
                            + '</li>';
                };
                log.imarea.append(log.html({
                    time: Datetime(0),
                    name: u.nick,
                    face: '../face/img.php?t=p1&u=' + u.chatid,
                    content: str
                }, u.chatid == My.chatid ? 'me' : ""));
                log.imarea.scrollTop(log.imarea[0].scrollHeight);
                //if(win.find('.layim_chatnow').attr('data-id'))
            }
        }
    })();

    UserList = (function() {
        var list = [];
        var OnLineUser = getId('OnLineUser');
        var OnlineUserNum = getId('OnlineUserNum');


        var RealUserNum = getId('RealUserNum');
        var OnlineOtherNum = getId('OnlineOtherNum');
        var PInfo = CreateElm(false, 'div', '', 'PInfo');
        var hold = 0;
        var show = 0;
        var onlinuser = OnlineUserNum.innerHTML;
        var realuser = 0;
        var onlinmyuser = 0;


        var def_list = $('#OnLineUser').html();
        list['ALL'] = {sex: 2, chatid: 'ALL', nick: '大家'}
        return{
            List: function() {
                return list
            },
            init: function() {
                list = [];
                //OnLineUser.innerHTML='';
                OnlineUserNum.innerHTML = OnlineUserNum.innerHTML ;
                RealUserNum.innerHTML = RealUserNum.innerHTML;


                list['ALL'] = {sex: 2, chatid: 'ALL', nick: '大家'}
                //UserList.add(My.chatid,My);

                if(check_auth('room_admin')){
                    //获取rebots在线列表
                    var request_url = '../ajax.php?act=getrlist&rid=' + My.rid + '&r=' + RoomInfo.r + '&' + Math.random() * 10000;
                    var xmlhttp = XHConn();
                    try {
                        xmlhttp.open("GET", request_url, true);
                        xmlhttp.send(null);
                        xmlhttp.onreadystatechange = function()
                        {
                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                            {

                                var Msg;
                                try {
                                    Msg = eval("(" + xmlhttp.responseText + ")");
                                } catch (e) {
                                    return;
                                }

                                if (Msg.stat == 'OK')
                                {

                                    OnlineUserNum.innerHTML = parseInt(Msg.count);
                                }
                                //alert(xmlhttp.responseText);
                                WriteMessage(xmlhttp.responseText);
                                //在线客服
                                UserList.getmylist(My.name);

                            }
                        }
                    }
                    catch (e) {
                        return null;
                    }
                }

            },
            get: function(id) {
                return list[id];
            },
            getmylist: function(user) {

                $.ajax({type: 'get', dataType: 'json', url: '../ajax.php?act=getmylist&rid=' + My.rid + '&user=' + encodeURIComponent(My.name),
                    success: function(data) {
                        //alert(data);
                        addmyuser = function(u) {
                            var li = CreateElm1(ref, 'li', false, 'myuser' + u.chatid, null);

                            var vip_ico = "";

                            var grp ='';//用户组显示
                            if(check_auth('room_admin')){
                                grp = grouparr[u.color].title + '-' + u.chatid;
                            }

                            vip_ico = "<img src='" + grouparr[u.color].ico + "'  align='top'/ title='" + grp + "'>";

                            //var vip_ico = "<img src='" + grouparr[u.gid].ico + "'  align='top'/ title='" + grouparr[u.gid].title + '-' + grouparr[u.gid].sn + "'>";
                            var iscam = '<span class="vipico">' + vip_ico + '</span>';

                            li.innerHTML = '<a href="javascript:void(0)"><font style="color:#FFF">'
                                    + iscam
                                    + '<cite><img src="../face/img.php?t=p1&u=' + u.chatid + '" border="0" class="head" /></cite>'
                                    + '<dt><strong id="cnick_' + u.chatid + '">' + u.nick + '</strong> &nbsp;<code> </code></dt>'
                                    + '<dl> </dl>'
                                    + '</font></a>';
                            if (u.gid == '3') {
                                li.innerHTML = li.innerHTML + '<p class="bts"><input type="button" value="私聊" class="osl"><input type="button" value="QQ对话" class="qsl"></p>';
                            }
                            li.oncontextmenu = function() {
                                UserList.menu_kf(u);
                                return false;
                            }
                            li.onclick = function() {
                                ToUser.set(u.chatid, u.nick);
                                openWin(2, false, 'profiles.php?uid=' + u.chatid, 460, 600);
                            }
                            //li.ondblclick=function(){if(u.chatid!=My.chatid||u.chatid.indexOf('x_r')<0){POPChat.newtab(u);POPChat.showtab(u);}}
                            $(li).find('.osl').click(function() {
                                if (u.chatid != My.chatid || u.chatid.indexOf('x_r') < 0) {
                                    POPChat.newtab(u);
                                    POPChat.showtab(u);
                                }
                                return false;
                            });
                            $(li).find('.qsl').click(function() {
                                window.open('http://wpa.qq.com/msgrd?v=3&uin=' + u.qq + '&site=qq&menu=yes');
                                return false;
                            });
                            if (UserList.get(u.chatid) == undefined) {
                                $(li).addClass('gray');
                            }
                        }

                        var ref = getId("group_myuser");
                        $('#group_myuser').html('');
                        onlinmyuser = 0;
                        if (data.state == 'true') {
                            for (var key in data.row) {

                                var u = data.row[key];
                                if ($("#myuser" + u.chatid)[0] == undefined) {
                                    onlinmyuser++;
                                    addmyuser(u);
                                }
                            }
                        }


                        OnlineOtherNum.innerHTML = onlinmyuser;
                    }

                });
            },
            plusXing:function(str,frontLen,endLen){
                var len = endLen-frontLen;
                var xing = '';
                for (var i=0;i<len;i++) {
                    xing+='*';
                }
                return str.substr(0,frontLen)+xing+str.substr(endLen);
            },
            checkPhone:function(phone){
                    if((/^1[34578]\d{9}$/.test(phone))){
                        return true;
                    }
            },
            add: function(id, u) {
                if ($("#" + id).length > 0)
                    return;
                var style = "";
                var vip_ico = "";

                var grp ='';//用户组显示
                if(check_auth('room_admin')){
                    grp = grouparr[u.color].title + '-' + grouparr[u.color].sn;
                }

                vip_ico = "<img src='" + grouparr[u.color].ico + "'  align='top'/ title='" + grp + "'>";



                onlinuser = parseInt(onlinuser);
                realuser = parseInt(realuser);

                if( !( u.age == '-') ){
                    realuser++;
                    onlinuser++;
                }


                OnlineUserNum.innerHTML = parseInt(onlinuser);
                RealUserNum.innerHTML = parseInt(realuser);

                u.nick = String(u.nick);
                if( UserList.checkPhone(u.nick)){
                    u.nick = UserList.plusXing(u.nick,3,9);
                }

                list[id] = u;
                var ref = getId("group_rebots");
                if (My.chatid == u.chatid) {
                    ref = getId("group_my");

                }
                else if (u.chatid.indexOf("x_r") >= 0)
                {
                    ref = getId("group_rebots");
                    if ($("#group_rebots").find("li").length > 50) {
                        return;
                    }
                }
                else
                {
                    ref = getId("group_" + u.color);
                }


                var li = CreateElm1(ref, 'li', false, id, null);

                var iscam = '<span class="vipico">' + vip_ico + '</span>';

                var faceimg = dfavatarNum();

                li.innerHTML = '<a href="javascript:void(0)"><font style="color:#FFF">'
                        + iscam
                        + '<cite><img onerror="" src="'+faceimg+'"  border="0" class="head" id="head_' + id + '"/><img src="images/state' + u.state + '.png" border="0" class="state" id="state' + id + '"/></cite>'
                        + '<dt><strong id="cnick' + id + '">' + u.nick + '</strong> &nbsp;<code>' + u.mood + '</code></dt>'
                        + '<dl>' + u.mood + '</dl>'
                        + '</font></a>';
                li.oncontextmenu = function() {
                    UserList.menu(u);
                    return false;
                }
                li.onclick = function() {
                    if (!check_auth("msg_ptp")) {
                        return;
                    }
                    ToUser.set(u.chatid, u.nick);
                }
                li.ondblclick = function() {

                }
                //if(u.vip>=2)
                //ColorNick('cnick'+id,parseInt(Math.random()*9));

                //getId('head_'+id).onmouseover =function(){UserList.info(id)}
                //li.onmouseover=function(){UserList.info(id)}
                //getId('head_'+id).onmouseout =UserList.infoHold;
                //li.onmouseout =UserList.infoHold;

            },
            setstate: function(id, state, automsg) {
                list[id].state = state;
                getId(id).title = automsg;
                getId('state' + id).src = "images/state" + state + ".png";
            },
            del: function(id, u) {
                if (id == My.chatid)
                    return;
                delete(list[id]);


                if( !( u.age == '-') ){
                    realuser--;
                    onlinuser--;
                }

                RealUserNum.innerHTML = realuser;

                OnlineUserNum.innerHTML = onlinuser;
                RemoveElm(OnLineUser, getId(id));
                ToUser.del(id);
            },
            info: function(id) {
                show = setTimeout(function() {
                    UserList.showInfo(id)
                }, 0);
            },
            showInfo: function(id) {
                if (hold)
                    clearTimeout(hold);
                var u = this.get(id);

                var t = getXY(getId(id));
                PInfo.style.top = t[0] - 142 + 'px';
                PInfo.style.left = t[1] + 248 + 'px';
                //PInfo.innerHTML='Login:'+u.roomid+'|'+u.chatid+'|'+u.nick+'|'+u.sex+'|'+u.age+'|'+u.guest+'|'+u.ip+'|'+u.vip+'|'+u.color+'|'+u.cam+'|'+u.headface+'|'+u.state+'|<br><br><br>'+u.automsg;
                var request_url = '../ajax.php?act=userinfo&type=json&id=' + id + '&' + Math.random() * 10000;
                var xmlhttp = XHConn();
                try {
                    xmlhttp.open("GET", request_url, true);
                    xmlhttp.send(null);
                    xmlhttp.onreadystatechange = function()
                    {
                        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
                        {
                            var UInfo = eval("(" + xmlhttp.responseText + ")");
                            if (My.vip > 0)
                                uip = " [ <a href='http://www.ip138.com/ips8.asp?ip=" + u.ip + "&action=1' target='_blank' title='点击查询地理位置'>" + u.ip + "</a> ]";
                            else
                                uip = "";
                            PInfo.innerHTML = '<div style="width:280px; height:150px; padding:6px;" class="info_m">'
                                    + '<div style="width:100px; height:150px; float:left; margin-right:6px; margin-bottom:6px" class="info_m_l"><img src="../face/img.php?t=p2&u=' + id + '" style="width:100px; height:150px;"></div>'
                                    + '<div style="float:left; width:174px; height:150px; overflow:hidden" class="info_m_r">'
                                    + '<div><a href="../profile.php?uid=' + id + '" target="userinfo"  style="cursor:pointer;color:#06C;">' + UInfo.nick + '</a></div><div style="color:#999" class="info_m_m">' + UInfo.sn + '</div><div class="info_m_">' + UInfo.rank + '</div><div><a href="../profile.php?uid=' + id + '" target="userinfo"  style="cursor:pointer;">' + UInfo.yx + '</a></div>'
                                    + '</div></div><div style="width:292px; height:20px; color:#000" >&nbsp;&nbsp;所在地：' + UInfo.city + uip + '</div>';
                            PInfo.style.display = '';
                            PInfo.style.cursor = 'default';
                        }
                    }

                } catch (e) {
                    return null;
                }

            },
            infoOver: function() {
                if (hold)
                    clearTimeout(hold);
            },
            infoHold: function() {
                hold = setTimeout(UserList.infoHidden, 500);
                PInfo.onmouseover = UserList.infoOver;
                PInfo.onmouseout = UserList.infoHold;
                if (show)
                    clearTimeout(show);
            },
            infoHidden: function() {
                PInfo.style.display = 'none';
            },
            infos: function(id) {
                var u = this.get(id);
                alert(u.nick)
            },
            setVideo: function(u) {
                SysSend.command('setVideo', My.rid + '_+_' + u.chatid + '_+_' + u.nick);
                getId('menu').style.display = 'none';
                var xmlhttp = XHConn();
                var request_url = "../ajax.php?act=setvideo&vid=" + u.chatid + "&rid=" + My.rid
                try {
                    xmlhttp.open('GET', request_url, true);
                    xmlhttp.send(null);
                }
                catch (e) {
                    return true;
                }
            },
            menu: function(u)
            {
                this.infoHidden();
                var UserMenu = Menu.init('120px');
                if (My.chatid == u.chatid)
                {
                    UserMenu.add('zl.gif', '个人资料', function() {
                        getId('menu').style.display = 'none';
                        openWin(2, false, 'profiles.php?uid=' + u.chatid, 460, 600);
                    });
                    if (RoomInfo.OtherVideoAutoPlayer == '0' && check_auth("room_admin"))
                        UserMenu.add('tv.gif', '上麦-房间主持人', function() {
                            UserList.setVideo(u);
                            getId('menu').style.display = 'none';
                        });
                }
                else
                {
                    UserMenu.hr();
                    UserMenu.add('zl.gif', '查看资料', function() {
                        getId('menu').style.display = 'none';
                        if (!check_auth("user_info")) {
                            layer.msg('没有用户资料查看权限！', {shift: 6});
                            return;
                        }
                        openWin(2, false, 'profiles.php?uid=' + u.chatid, 460, 600);
                    });
                    UserMenu.hr();
                    UserMenu.add('pb.gif', '屏蔽消息', function() {
                        BList.add(u.chatid, u);
                        getId('menu').style.display = 'none';
                    });

                    if (check_auth("room_admin"))
                    {
                        UserMenu.hr();
                        UserMenu.add('Admin.gif', '禁言', function() {
                            ToUser.set(u.chatid, u.nick);
                            SysSend.command('send_Msgblock', '');
                        });
                        UserMenu.add('Admin.gif', '踢出、封IP', function() {
                            getId('menu').style.display = 'none';
                            if (!check_auth("user_kick")) {
                                layer.msg('没有用户踢出权限！', {shift: 6});
                                return;
                            }
                            UKick.ShowMb(u);
                        });
                        if (RoomInfo.OtherVideoAutoPlayer == '0')
                            UserMenu.add('tv.gif', '上麦-房间主持人', function() {
                                UserList.setVideo(u);
                                getId('menu').style.display = 'none';
                            });
                    }
                }
                var e = getEvent();
                UserMenu.display(e.clientX, e.clientY);
            },
            menu_kf: function(u)
            {
                this.infoHidden();
                var UserMenu = Menu.init('120px');
                if (My.chatid == u.chatid)
                {
                    UserMenu.add('zl.gif', '个人资料', function() {
                        getId('menu').style.display = 'none';
                        openWin(2, false, 'profiles.php?uid=' + u.chatid, 460, 600);
                    });
                    if (RoomInfo.OtherVideoAutoPlayer == '0' && check_auth("room_admin"))
                        UserMenu.add('tv.gif', '上麦-房间主持人', function() {
                            UserList.setVideo(u);
                            getId('menu').style.display = 'none';
                        });
                }
                else
                {
                    UserMenu.hr();
                    UserMenu.add('zl.gif', '查看资料', function() {
                        getId('menu').style.display = 'none';
                        openWin(2, false, 'profiles.php?uid=' + u.chatid, 460, 600);
                    });
                    UserMenu.hr();
                    UserMenu.add('pb.gif', '屏蔽消息', function() {
                        BList.add(u.chatid, u);
                        getId('menu').style.display = 'none';
                    });

                    if (check_auth("room_admin"))
                    {
                        UserMenu.hr();
                        UserMenu.add('Admin.gif', '禁言', function() {
                            ToUser.set(u.chatid, u.nick);
                            SysSend.command('send_Msgblock', '');
                        });
                        UserMenu.add('Admin.gif', '踢出、封IP', function() {
                            getId('menu').style.display = 'none';
                            if (!check_auth("user_kick")) {
                                layer.msg('没有用户踢出权限！', {shift: 6});
                                return;
                            }
                            UKick.ShowMb(u);
                        });
                        if (RoomInfo.OtherVideoAutoPlayer == '0')
                            UserMenu.add('tv.gif', '上麦-房间主持人', function() {
                                UserList.setVideo(u);
                                getId('menu').style.display = 'none';
                            });
                    }
                }
                var e = getEvent();
                UserMenu.display(e.clientX, e.clientY);
            }
        }
    })();
    PublicVideo = (function() {

    })();
    UKick = (function() {
        return{
            ShowMb: function(u) {
                var loadstr = '<div  id="kickmp" onselectstart="return true;">';
                loadstr += '<select name="MCmd" id="MCmd" onchange="if(this.value==\'kick\')getId(\'ktime\').style.display=\'\'"><option value="kick">踢出</option></select>';
                loadstr += '&nbsp;<select id="ktime" name="ktime">      <option value="0">踢出房间</option>      <option value="1">禁闭01分钟</option>      <option value="10">禁闭10分钟</option>      <option value="30">禁闭30分钟</option>      <option value="60">禁闭60分钟</option>      <option value="720">禁闭12小时</option>      <option value="10080">禁闭1星期</option></select>';
                loadstr += '<br><br><input type="text" name="cause" id="cause" value="未知" size="24" /><br><button class="bt1" onclick="UKick.SendCmd(\'' + u.chatid + '\',\'' + u.nick + '\')">执行</button>';
                loadstr += '</div>';
                openWin(1, '踢出 ' + u.nick, loadstr, 290, 200);
            },
            SendCmd: function(chatid, nick) {
                ToUser.set(chatid, nick);
                SysSend.command('kick', getId('ktime').value + '_+_' + getId('cause').value);
            }
        }
    })();
    BList = (function() {
        var List = [];
        return{
            init: function() {
                List = []
            },
            add: function(id, u) {
                if (BList.isExist(id)) {
                    BList.del(id);
                    return;
                }
                List[id] = u;
                UserList.setstate(id, '00', '已经屏蔽消息');
            },
            isExist: function(id) {
                var r = false;
                for (key in List) {
                    if (id == List[key].chatid) {
                        return true;
                    }
                }
                return r;
            },
            del: function(id) {
                UserList.setstate(id, '0', '');
                delete List[id];
            }
        }
    })();

    ToUser = (function() {
        $('#ToUser').change(function() {
            ToUser.set($(this).val(), $(this).find("option:selected").text());
        });
        return{
            id: null,
            name: null,
            add: function(id, name) {
                $('#ToUser option[value=' + id + ']').remove();
                $("#ToUser").append("<option value='" + id + "'>" + name + "</option>");
                $('#ToUser option[value=' + id + ']').attr('selected', 'selected');

            },
            del: function(id) {
                $('#ToUser option[value=' + id + ']').remove();
            },
            set: function(id, name) {
                if (id == My.chatid)
                    return;
                this.id = id;
                this.name = name;
                this.add(id, name);
            }
        }
    })();
    VideoList = (function() {
        var Video_list = getId('Video_List');
        return{
            t: 0,
            Connect: function(Uid, Name, type) {
                //if(Uid==My.chatid){alert('视频设置...制作中！');return;}
                if (type == '0') {
                    if (Uid == 'ALL') {
                        alert('请选网友！');
                        return;
                    }
                    if (!confirm("确定和'" + Name + "'视频密聊"))
                        return;
                    ToUser.set(Uid, Name);
                    SysSend.command('requestVideo', My.chatid + '_+_' + My.nick);
                    this.PrivateConnect(Uid, Name);
                    return;
                }
                this.t++;
                var vC = Video_list.getElementsByTagName('div');
                if (vC.length >= RoomInfo.MaxVideo)
                    RemoveElm(Video_list, vC[0])
                if (getId('V' + My.rid + '·' + Uid) != null)
                    RemoveElm(Video_list, getId('V' + My.rid + '·' + Uid));
                var div = CreateElm(Video_list, 'div', 'list', 'V' + My.rid + '·' + Uid);

                var vFlash = new SWFObject('images/Video_list.swf?Server=' + RoomInfo.VServer + '&User=' + Name + '&Uid=' + My.rid + '·' + Uid, "Video_more", "148", "110", "9", "#FFF");
                vFlash.addParam("wmode", "transparent");
                vFlash.addParam("allowFullScreen", "true");
                vFlash.addParam("allowScriptAccess", "sameDomain");
                vFlash.write('V' + My.rid + '·' + Uid);
                return;
            },
            PrivateConnect: function(TUid, TName) {
                alert('开发中……');
                /*
                 getId('PInfo').style.display='none';
                 
                 var L=My.chatid+'-'+TUid;
                 var R=TUid+'-'+My.chatid;
                 var div='<embed type="application/x-shockwave-flash" src="images/Video.swf?active=true&L='+L+'&R='+R+'&S='+RoomInfo.VServer+'&Q='+RoomInfo.VideoQ+'" width="340" height="360" bgcolor="#FFF" quality="high" allowfullscreen="true" allowscriptaccess="sameDomain">';
                 openWin(1,'和 '+TName+'视频聊天',div,340,360);
                 
                 var sFlash = new SWFObject("images/Video.swf?active=true&L="+L+"&R="+R+'&S='+RoomInfo.VServer+'&Q='+RoomInfo.VideoQ, "FVideo"+TUid, "340", "360", "9", "#FFF");
                 //sFlash.addParam("wmode","transparent");
                 sFlash.addParam("allowFullScreen","true");
                 sFlash.addParam("allowScriptAccess","sameDomain");
                 sFlash.write('Video'+TUid);
                 */
                return;

            },
            Close: function(TUid) {
                if (getId('PV' + TUid) != null)
                    RemoveElm(getId('UI_MainBox'), getId('PV' + TUid));
                getId('PV' + TUid).style.display = 'none';
                return;
            }
        }
    })();
    var oldMsg;
    var oldTime;
    var msgTag = false;
    SysSend = (function() {
        return{
            isUser: function()
            {
                if (ToUser.id.indexOf('x_r') > -1) {
                    ToUser.set('ALL', '大家');
                }
                var toUserInfo = UserList.get(ToUser.id);
                if (typeof (toUserInfo) == "undefined") {
                    alert('对方已经离线！');
                    ToUser.del(ToUser.id);
                    return false;
                }
                if (ToUser.id == 'ALL') {
                    alert('先选择一个网友！');
                    return false;
                }
                return true;
            },
            msg: function(msg_type) {
                if (!check_auth("msg_send")) {
                    layer.msg('没有发言权限！', {shift: 6});
                    return false;
                }


                if((des_msg == 1 || des_msg == "1"  )&&!check_auth("room_admin")){
                    layer.msg('禁止发言！', {shift: 6});
                    return false;
                }

                if ($("#msg_tip_marquee").attr("checked")) {
                    $("#msg_tip_marquee").attr("checked", false);
                    SysSend.command('barrage', encodeURIComponent(getId('Msg').innerHTML));
                    return true;
                }
                if ($("#chat_type").val() == "he" && ToUser.id != "ALL") {
					var Msg = getId('Msg').innerHTML;
					var Style = "font-weight:" + getId('Msg').style.fontWeight + ";font-style:" + getId('Msg').style.fontStyle + "; text-decoration:" + getId('Msg').style.textDecoration + ";color:" + getId('Msg').style.color + "; font-family:" + getId('Msg').style.fontFamily + "; font-size:" + getId('Msg').style.fontSize;
					var msgid = randStr() + randStr();
					PutMessage(My.rid, $('#ToUser').val(), 'ALL', $('#ToUser option:selected').html(), '大家', 'false', Style, Msg, msgid);
                    SysSend.command('rebotmsg', encodeURIComponent(getId('Msg').innerHTML));
                    return true;
                }

                if (ToUser.id != "ALL")
                    if (!this.isUser())
                        return false;
                var toUserInfo = UserList.get(ToUser.id);
                if (toUserInfo.state == '00')
                    alert("注意:" + toUserInfo.nick + ' 的消息你已经屏蔽,你将收不到来自ta的消息');
                if (typeof (toUserInfo) == "undefined") {
                    alert('对方已经离线！');
                    ToUser.del(ToUser.id);
                    return false;
                }
                var Msg = getId('Msg').innerHTML;
                var Style = "font-weight:" + getId('Msg').style.fontWeight + ";font-style:" + getId('Msg').style.fontStyle + "; text-decoration:" + getId('Msg').style.textDecoration + ";color:" + getId('Msg').style.color + "; font-family:" + getId('Msg').style.fontFamily + "; font-size:" + getId('Msg').style.fontSize;
                var Msg = encodeURIComponent(Msg.str_replace());

                var newTime = new Date().getTime();

                if(!check_auth("room_admin")){
                    if (newTime - oldTime < 5000) {
                        layer.msg('发言时间间隔为五秒！', {shift: 6});
                        return;
                    }
                    if (msgTag) {
                        if (newTime - oldTime > 5000)
                            msgTag = false;
                        else {
                            layer.msg('发言时间间隔为五秒！', {shift: 6});
                            return;
                        }
                    }
                }

                if (Msg != '')
                {
                    var msgid = randStr() + randStr();
                    if(msg_type == '2') {
                        // var str = 'SendMsgByRobot=M=' + ToUser.id + '|' + getId('Personal').value + '|' + Style + '|' + msgid + '_+_' + Msg + '|' + My.qx;
                        ws.send('{"type":"SendMsgByRobot","touser":"'+ToUser.id+'","IsPersonal":"'+getId('Personal').value+'","Style":"'+Style+'","Msg":"'+ msgid + '_+_' + Msg +'","qx":"'+My.qx+'"}');

                    }else {
                        ws.send('{"type":"say","touser":"'+ToUser.id+'","IsPersonal":"'+getId('Personal').value+'","Style":"'+Style+'","Msg":"'+ msgid + '_+_' + Msg +'","qx":"'+My.qx+'"}');
                        // var str = 'SendMsg=M=' + ToUser.id + '|' + getId('Personal').value + '|' + Style + '|' + msgid + '_+_' + Msg +'|' +My.qx;
                    }

                    // socket.emit('message', str);



                    var Msgflow = [];
                    Msgflow.push('%3Cimg%20src%3D%22%2Froom%2Fskins%2Fchatimg%2Fflower.png%22%20class%3D%22flower_png%22%20border%3D%220%22%20alt%3D%22%22%20height%3D%2220px%3B%22%3E');
                    Msgflow.push('%3Cimg%20src%3D%22%2Froom%2Fskins%2Fchatimg%2Fgeili.gif%22%20class%3D%22flower_png%22%20border%3D%220%22%20alt%3D%22%22%20height%3D%2220px%3B%22%3E');
                    Msgflow.push('%3Cimg%20src%3D%22%2Froom%2Fskins%2Fchatimg%2Fguzhang.png%22%20class%3D%22guzhang_png%22%20border%3D%220%22%20alt%3D%22%22%20height%3D%2220px%3B%22%3E');
                    Msgflow.push('%3Cimg%20src%3D%22%2Froom%2Fskins%2Fchatimg%2Fding.png%22%20class%3D%22ding_png%22%20border%3D%220%22%20alt%3D%22%22%20height%3D%2220px%3B%22%3E');
                    Msgflow.push('%3Cimg%20src%3D%22%2Froom%2Fskins%2Fchatimg%2Fzan_icon.png%22%20class%3D%22zan_png%22%20border%3D%220%22%20alt%3D%22%22%20height%3D%2220px%3B%22%3E');


                    if(My.rbnum > 0 &&  msg_type ==2){
                        var length =$("#group_rebots  li").length;

                        var items =[1];
                        $("#group_rebots  li").each(function(index,e){
                            items.push(index+1);
                            if((index+1) > My.rbnum ){
                                return false;
                            }
                        });

                        function final(value) {
                            console.log('完成: ', value);
                        }
                        var results = [];

                        var running = 0;
                        var limit = 1;
                        function launcher(){
                            while(running < limit && items.length > 0){
                                var item = items.shift();
                                async(item, function(result){

                                    if($.inArray(Msg, Msgflow)>-1){
                                        var  rannum= parseInt(4*Math.random());
                                        Msg= Msgflow[rannum];
                                    }

                                    var randomid = length*Math.random();
                                    var  uid = $("#group_rebots  li").eq(randomid).prop('id');
                                    // var str = 'SendMsgByRobot=M=' + ToUser.id + '|' + getId('Personal').value + '|' + Style + '|' + msgid + '_+_' + Msg +'|' +My.qx+'|' +uid;


                                    ws.send('{"type":"SendMsgByRobot","touser":"'+ToUser.id+'","IsPersonal":"'+getId('Personal').value+'","Style":"'+Style+'","Msg":"'+ msgid + '_+_' + Msg +'","qx":"'+My.qx+'"}');

                                    results.push(result);
                                    running--;
                                    if(items.length > 0){
                                        launcher();
                                    }else if(running == 0){
                                        final(results);
                                    }
                                });
                                running++;
                            }
                        }
                        launcher();
                    }

                    oldMsg = Msg;
                    oldTime = new Date().getTime();
                    getId('Msg').innerHTML = '';
                    getId('Msg').focus();

                    if(!(msg_type ==2)) {
                        PutMessage(My.rid, My.chatid, ToUser.id, My.nick, toUserInfo.nick, getId('Personal').value, Style, Msg, msgid);
                    }
                }
                return true;
            },
            command: function(cmd, value) {
                var Msg = '';
                var IsPersonal = getId('Personal').value;
                var Style = "font-weight:" + getId('Msg').style.fontWeight + ";font-style:" + getId('Msg').style.fontStyle + "; text-decoration:" + getId('Msg').style.textDecoration + ";color:" + getId('Msg').style.color + "; font-family:" + getId('Msg').style.fontFamily + "; font-size:" + getId('Msg').style.fontSize;
                switch (cmd)
                {
                    case 'setVideoSrc':
                        Msg += 'C0MMAND_+_' + cmd + '_+_' + value;
                        IsPersonal = 'false';
                        break;
                    case 'send_Msgblock':
                        Msg += 'C0MMAND_+_' + cmd + '_+_' + value;
                        IsPersonal = 'true';
                        break;
                    case 'msgBlock':
                        Msg += 'C0MMAND_+_' + cmd + '_+_' + value;
                        IsPersonal = 'false';
                        break;
                    case 'kick':
                        Msg += 'C0MMAND_+_' + cmd + '_+_' + value;
                        IsPersonal = 'true';
                        break;
                    case 'magicflash':
                        if (this.isUser())
                        {
                            Msg += 'C0MMAND_+_' + cmd + '_+_' + value;
                            IsPersonal = getId('Personal').value;
                        }
                        break;
                    case 'requestVideo':
                        if (this.isUser())
                        {
                            Msg += 'C0MMAND_+_' + cmd + '_+_' + value;
                            IsPersonal = 'true';
                        }
                        break;
                    case 'setstate':
                        //ToUser.id='ALL';
                        Msg += 'C0MMAND_+_' + cmd + '_+_' + My.chatid + '_+_' + value;
                        IsPersonal = 'false';
                        break;
                    case 'rebotmsg':
                        Msg += 'C0MMAND_+_' + cmd + '_+_' + ToUser.id + '_+_' + value;
                        IsPersonal = 'false';
                        break;
                    case 'barrage':
                        Msg += 'C0MMAND_+_' + cmd + '_+_' + ToUser.id + '_+_' + value;
                        IsPersonal = 'false';
                        break;
                    default:
                        Msg += 'C0MMAND_+_' + cmd + '_+_' + value;
                        IsPersonal = 'false';
                        //ToUser.id='ALL';
                        break;
                }
                if (Msg != '')
                {
                    var touser = ToUser.id;
                    if (ToUser.id.indexOf('x_r') > -1) {
                        touser = 'ALL';
                    }
                    // var str = 'SendMsg=M=' + touser + '|' + IsPersonal + '|' + Style + '|' + Msg + '|' + My.qx;
                    // socket.emit('message', str);

                    ws.send('{"type":"say","touser":"'+touser+'","IsPersonal":"'+IsPersonal+'","Style":"'+Style+'","Msg":"'+Msg+'","qx":"'+My.qx+'"}');

                    alert('操作成功');
                    getId('Msg').innerHTML = '';
                    getId('Msg').focus();
                }
            }
        }
    })();
    Menu = (function() {
        var MObj;
        return{
            init: function(w) {
                RemoveElm(false, getId('menu'))
                this.MObj = CreateElm(false, 'div', false, 'menu');
                this.MObj.tabIndex = 1;
                this.MObj.style.width = w;
                this.MObj.style.display = 'none';
                this.MObj.style.zIndex = 1;
                return this;
            },
            add: function(icon, txt, fun) {
                var n = CreateElm(this.MObj, 'div', 'out', 'n');
                n.onmouseout = function() {
                    n.className = 'out';
                }
                n.onmouseover = function() {
                    n.className = 'over';
                }
                n.innerHTML = '<div id="icon" ><img src="images/' + icon + '" /></div><span id="txt">' + txt + '</span>';
                n.onclick = fun;
            },
            hr: function() {
                var n = CreateElm(this.MObj, 'div', 'hr', 'n');
                n.style.height = '1px';
                n.style.fontSize = '1px';
            },
            display: function(x, y) {
                this.MObj.style.display = '';
                this.MObj.style.top = y + 'px';
                this.MObj.style.left = x + 'px';

                this.MObj.focus();
                this.MObj.onblur = function() {
                    BrdBlur('menu');
                }

            }
        }
    })();
}
function WriteMessage(txt) {

    var Msg;
    try {
        Msg = eval("(" + txt + ")");
    } catch (e) {
        return;
    }
    if (Msg.stat != 'OK')
    {
        if (Msg.stat == "des_msg") {
            if(globalgid ==Msg.roomid ){
                des_msg = Msg.des_msg;
            }
            return;
        }

        if (Msg.stat == "send_gif") {
            $('#gift_super').attr('data','skins/gift/'+Msg.data_str.gift_id+'_188.swf');
           $('#gifcontainer').show();

            rideHorse(Msg.data_str.nick+'送出'+Msg.data_str.gift_name+'x'+Msg.data_str.num);

            setTimeout("$('#gifcontainer').hide()",10000);

            return;
        }

        if (Msg.stat == "black_bord") {
            if(globalgid ==Msg.roomid ){
                st_time = Msg.st_time;
                end_time = Msg.end_time;
                ico = Msg.ico;

                $('.line_ad').attr('start_time',st_time);
                $('.line_ad').attr('end_time',end_time);
                $('.line_ad img').attr('src',ico);
                setBlackSate();
            }
            return;
        }

        if (Msg.stat == "bg_music") {

            if(globalgid ==Msg.roomid ){
                mst_time = Msg.st_time;
                mend_time = Msg.end_time;

                $('#audio1').attr('start_time',mst_time);
                $('#audio1').attr('end_time',mend_time);
                setMusicSate();
            }
            return;
        }

        //更新机器人
        if (Msg.stat == "set_robot") {
            if(globalgid ==Msg.roomid ){
                var OnlineUserNum = getId('OnlineUserNum');
                var RealUserNum = getId('RealUserNum').innerHTML ;
                OnlineUserNum.innerHTML =parseInt(RealUserNum)+parseInt(Msg.robot_num);
            }
            return;
        }
        //禁言
        if (Msg.stat == "ban_word") {

            if(My.chatid == Msg.uid ){
                remove_auth('msg_send');
            }
            return;
        }
        //充值
        if (Msg.stat == "recharge") {
            if(My.chatid == Msg.uid ){
                My.diamond = parseInt(My.diamond)+parseInt(Msg.cost);
            }
            return;
        }

        if (Msg.stat == "MaxOnline") {
            document.body.innerHTML = '<div  style="font-size:12px; text-align:center; top:100px; position:absolute;width:100%">O.O 对不起，服务端并发数已满！请您联系管理员对系统扩容升级！<br><br></div>';
            return;
        }
        if (Msg.stat == "OtherLogin") {
            location.href = "error.php?msg=" + encodeURI('其他地方登录！请注意同一帐号不能两处登录、同一电脑不能两处打开房间！')
        }
        return;
    }
    switch (Msg.type)
    {
        case "Ulogin":

            var U = Msg.Ulogin;
			if(U.chatid == '-1' || U.chatid == '-2')
				return;
            var vip_msg = "到来";
            var date = Datetime(0);
            //var str = '<div style="height:22px; line-height:22px;">欢迎：<font class="u" onclick="ToUser.set(\'' + U.chatid + '\',\'' + U.nick + '\')">' + U.nick + '</font> <font class="date">' + date + '</font></div>';
			var str = '欢迎：' + U.nick + ' ' + date;
            if (My.chatid != U.chatid) {
                UserList.add(U.chatid, U);
            }
            var type = 0;
            if (U.chatid == My.chatid)
                type = 2;

            break;
        case "UMsg":

            var txt = Msg.UMsg.Txt.split('_+_');

            var str = FormatMsg(Msg.UMsg);
           if(!str){
               return false;
           }
            var type = 0;
            if (!str)
                return;
            if (BList.isExist(Msg.UMsg.ChatId))
                return;
            if (Msg.UMsg.ToChatId == My.chatid) {
                type = 2;
                MsgAlert(0);
                if (audioNotify == true)
                    playSound('msg.mp3');
            }weishenme

            if (Msg.UMsg.ChatId == My.chatid)
                type = 2;

            if (Msg.UMsg.ToChatId == 'ALL') {
                if (Msg.UMsg.ChatId == My.chatid)
                    type = 2;
                else
                    type = 0;
            }
            if (Msg.UMsg.IsPersonal != 'true') {
                MsgShow(str, type);
            } else {
                if (Msg.UMsg.ChatId == My.chatid) {
                    POPChat.newtab(UserList.get(Msg.UMsg.ToChatId));
                }
                else {
                    POPChat.newtab(UserList.get(Msg.UMsg.ChatId));
                }
                POPChat.showmsg(UserList.get(Msg.UMsg.ChatId), UserList.get(Msg.UMsg.ToChatId), "<font style='" + Msg.UMsg.Style + "'>" + decodeURIComponent(Msg.UMsg.Txt.str_replace()) + "</font>");
            }
            break;
        case "UonlineUser":
            var onlineNum = Msg.roomListUser.length;
            for (i = 0; i < onlineNum; i++)
            {
                var U = Msg.roomListUser[i];
				if(U.chatid == '-1' || U.chatid == '-2')
					continue;
                UserList.add(U.chatid, U);
            }
            break;
        case "Ulogout":
            var U = Msg.Ulogout;
			if(U.chatid == '-1' || U.chatid == '-2')
				return;
            var date = Datetime(0);
            //var str = '<div style="height:22px; line-height:22px;">用户：<font class="u" onclick="ToUser.set(\'' + U.chatid + '\',\'' + U.nick + '\')">' + U.nick + '</font>   离开！ <font class="date">' + date + '</font></div>';
			var str = U.nick + '   离开！ ' + date;            
			
			//MsgShow(str, 0);
            UserList.del(U.chatid, U);
			notice(str);
			//MsgAutoScroll();
            break;
        case "SPing":
            //alert(Msg.SPing.time);
            break;
        case "Sysmsg":
            alert(Msg.Sysmsg.txt);
            break;
    }

}

function notice(str) {
	if($('.notice span').length >= 3)
		$('.notice span').get(0).remove();
	$('.notice').append('<span>' + str + '</span>');
}

function CommObjectCheck(obj, inObj)
{
    if (obj == inObj)
    {
        return true;
    }
    if (obj.parentNode) {
        return CommObjectCheck(obj.parentNode, inObj);
    }
    return false;
}
function CreateElm(pObj, obj, className, id) {
    var elm = null;
    var elm = document.createElement(obj);
    if (!pObj)
        document.body.insertBefore(elm, null);
    else
        pObj.insertBefore(elm, null);
    if (id)
        elm.id = id;
    if (className)
        elm.className = className;
    return elm
}
function CreateElm1(pObj, obj, className, id, ref) {
    var elm = null;
    var elm = document.createElement(obj);
    if (!pObj)
        document.body.insertBefore(elm, ref);
    else
        pObj.insertBefore(elm, ref);
    if (id)
        elm.id = id;
    if (className)
        elm.className = className;
    return elm
}


function RemoveElm(pObj, id)
{
    $(id).html("");
    $(id).remove()
}


String.prototype.str_replace = function(qx) {
    var str = this;
    var reg = new RegExp(msg_unallowable, "ig");
    if(qx == 0){
        var mystr= str.replace(/<img.*>/ig,'');

        if (reg.test(mystr) && !check_auth("room_admin"))
            return "含敏感关键字，内容被屏蔽";
        str = str.replace(/<\/?(?!br|img|font|p|span|\/font|\/p|\/span)[^>]*>/ig, '').replace(/\r?\n/ig, ' ').replace(/(&nbsp;)+/ig, " ").replace(/(=M=)+/ig, "").replace(/(|)+/ig, "").replace(/(SendMsg)/ig, '');
        //if (!check_auth("room_admin"))  str = str.replace(reg, '**')
        return str;
    }

    return str;

};
function LinkMaker(str) {
    return str.replace(/(https?:\/\/[\w.]+[^ \f\n\r\t\v\"\\\<\>\[\]\u2100-\uFFFF]*)|([a-zA-Z_0-9.-]+@[a-zA-Z_0-9.-]+\.\w+)/ig, function(s, v1, v2) {
        if (v2)
            return ['<a href="mailto:', v2, '">', v2, '</a>'].join("");
        else
            return ['<a href="', s, '">', s, '</a>'].join("");
    });
}
function SwapLink()
{
    if (!isIE)
        getId('Msg').innerHTML = LinkMaker(getId('Msg').innerHTML);

    var as = getId('Msg').getElementsByTagName('a');
    for (var i = as.length - 1; i >= 0; i--) {
        as[i].target = '_blank';
        as[i].className = 'MsgUrlStyle';
    }
}
function PutMessage(rid, uid, tid, uname, tname, privacy, style, str, msgid) {
    var msgtip = "";

    if ($("#msg_tip").attr("checked")) {
        msgtip = "msgtip=2&";
        $("#msg_tip").attr("checked", false);
        $("#msg_tip_show").html(decodeURIComponent("<span style='color:#FF0'>" + str + "</span>"));

    } else if ($("#msg_tip_admin").attr("checked")) {
        msgtip = "msgtip=3&";
        $("#msg_tip_admin").attr("checked", false);
        $("#msg_tip_admin_show").html(decodeURIComponent("<span style='color:red'>" + str + "</span>"));
    }
    if (RoomInfo.Msglog == '0')
        return;
    var request_url = '../ajax.php?act=putmsg';
    var postdata = msgtip + 'msgid=' + msgid + '&uname=' + encodeURIComponent(uname) + '&tname=' + encodeURIComponent(tname) + '&muid=' + uid + '&rid=' + rid + '&tid=' + tid + '&privacy=' + privacy + '&style=' + style + '&msg=' + str + '&' + Math.random() * 10000;

    $.ajax({type: 'POST', url: request_url, data: postdata});
}
function delHtmlTag(str){
    return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
}
function Mkick(adminid, rid, ktime, cause)
{
    $.ajax({type: 'get', dataType: 'json', url: '../ajax.php?act=kick&aid=' + adminid + '&rid=' + rid + '&ktime=' + ktime + '&cause=' + encodeURIComponent(cause) + '&u=' + encodeURIComponent(My.name) + '&' + Math.random() * 10000,
        success: function(data) {
            //alert(data);
            if (data.state == "yes") {
                // location.href = "error.php?msg=" + encodeURI('你被踢出！并禁止' + ktime + '分钟内登陆该房间！<br>原因是 ' + cause + '');
                location.href = "error.php";
            }
        }
    });
}
function kick_send(adminid)
{
    $.ajax({type: 'get', dataType: 'json', url: '../ajax.php?act=kick_send&aid='+adminid+'&u=' + encodeURIComponent(My.name) + '&' + Math.random() * 10000,
        
    });
}

function FormatMsg(Msg)
{
    var User = UserList.get(Msg.ChatId);
    var toUser = UserList.get(Msg.ToChatId);
    var date = getNowFormatDate();
    var IsPersonal = '';
    if ( typeof (toUser) == 'undefined'){
        return false;
    }
    //机器人格式话
    if(typeof (User) == 'undefined' ){
        var ss = new Array();
        for(var pro in grouparr) {
            if(pro != '2' &&  pro != '0'&&  pro != '4' ){
                ss.push(pro);
            }
        }
        var num = parseInt(Math.random() * ss.length);

        User = {chatid: "123456", color: ss[0], ip: "127.0.0.1", mood: "", nick: randomWord(true, 2, 8),qx:"0",roomid:"/1",sex:"0",state:"0",vip:ss[num]}
    }

    if (Msg.IsPersonal == 'true' && toUser.chatid != 'ALL')
        IsPersonal = '[私]';

    var Txt = decodeURIComponent(Msg.Txt);
    var  Txt = Txt.str_replace(Msg.qx);

    if(Txt.indexOf("含敏感关键字") >= 0 ){
        // layer.msg('含敏感关键字！', {shift: 6});
        return false;
    }

    if (Txt.indexOf('C0MMAND') != -1)
    {
        var command = Txt.split('_+_');
        switch (command[1])
        {
            case 'setVideoSrc':
                $('#defvideosrc i').html(command[3]);
                var date = getNowFormatDate();
                var str = '<div style="height:22px; line-height:22px;font-size: 16px;padding-left: 5px;">欢迎：<font class="u" ">讲师-' + command[3] + '</font>开讲啦！ <font style="margin-right:5px" class="date">' + date + '</font></div>';

                break;
            case 'send_Msgblock':
                if (My.chatid == toUser.chatid) {
                    remove_auth('msg_send');
                    layer.msg('你已被禁言！', {shift: 6});
					kick_send(Msg.ChatId);
                }
                break;
            case 'msgAudit':
                $('#' + command[2]).show();
                //MsgAutoScroll();
                $.ajax({type: 'get', url: '../ajax.php?act=msgblock&s=0&msgid=' + command[2]});
                break;
            case 'msgBlock':
                $('#' + command[2]).remove();
                //MsgAutoScroll();
                $.ajax({type: 'get', url: '../ajax.php?act=msgblock&s=1&msgid=' + command[2]});
                break;
            case 'rebotmsg':
                var msg = {};
                msg.ChatId = command[2];
                msg.ToChatId = 'ALL';
                msg.IsPersonal = 'false';
                msg.Txt = command[3];
                msg.Style = Msg.Style;
                MsgShow(FormatMsg(msg), 0);
                break;

            case 'kick':


                if (My.chatid == toUser.chatid) {
                    Mkick(Msg.ChatId, My.roomid, command[2], command[3]);
                }
                break;
            case 'requestVideo':
                if (command[2] == My.chatid)
                    return;
                if (!confirm(command[3] + ' 请求和你视频，是否接受？'))
                    return;
                ToUser.set(command[2], command[3]);
                VideoList.PrivateConnect(command[2], command[3]);
                return;
                //SysSend.command('requestVideo',Uid+'_+_'+Name);

                break;
            case 'setstate':
                UserList.setstate(command[2], command[3], command[4]);
                break;
            case 'setVideo':
                toUser = UserList.get(command[3]);
                var str = '<div style="height:22px; line-height:22px;">' + IsPersonal + '<font class="u" color="' + aColor[User.sex] + '" onclick="ToUser.set(\'' + User.chatid + '\',\'' + User.nick + '\')">' + User.nick + '</font> 设置 <font class="u" color="' + aColor[toUser.sex] + '" onclick="ToUser.set(\'' + toUser.chatid + '\',\'' + toUser.nick + '\')">' + toUser.nick + '</font> 为房间公共视频  <font class="date">' + date + '</font></div>';
                try {

                    if (RoomInfo.OtherVideoAutoPlayer != "0") {

                        $('#OnLine_MV').html('<iframe height="390" width="100%" allowTransparency="true" marginwidth="0" marginheight="0"  frameborder="0" scrolling="no" src="player.php?type=pc&rid='+globalgid+'"></iframe>');

                    }

                    else if (command[3] == My.chatid)
                    {
                        thisMovie('pVideo').stopS(RoomInfo.AutoSelfVideo);
                        thisMovie('pVideo').sConnect(RoomInfo.VServer, command[2] + '·' + command[3], '1');
                        //thisMovie('pVideo').pShow("2",toUser.nick);
                    }
                    else
                    {
                        thisMovie('pVideo').stopS(RoomInfo.AutoSelfVideo);
                        thisMovie('pVideo').pConnect(RoomInfo.VServer, command[2] + '·' + command[3], toUser.nick);

                    }
                } catch (e) {
                }
                break;
            case "sendgift":
                //('sengift','{$uid}_+_{$sid}_+_{$gid}_+_{$num}_+_{$gname}_+_{$msg}')
                var u = UserList.get(command[2]);
                var s = UserList.get(command[3]);
                for (var i = 1; i <= command[5]; i++) {
                    if (i > 300)
                        break;
                    setTimeout('ShowGifteffect("' + command[4] + '")', 10 * i);
                }
                var str = '<p><font class="u" color="' + aColor[u.sex] + '" onclick="ToUser.set(\'' + u.chatid + '\',\'' + u.nick + '\')">' + u.nick + '</font> 向 <font class="u" color="' + aColor[s.sex] + '" onclick="ToUser.set(\'' + s.chatid + '\',\'' + s.nick + '\')">' + s.nick + '</font> 送了<img src="../gift/img.php?id=' + command[4] + '" height="50" width="50"/> (<span style="color:red"><b>' + command[5] + '</b></span>份) ' + command[6] + ' <font color="' + aColor[u.sex] + '">赠言： ' + command[7] + '</font> <font class="date">' + date + '</font></p>';
				break;
            case 'barrage':
				if($('#msg_tip_marquee_show').html() != undefined) {
					$('#msg_tip_marquee_show').remove();
				}
                $("body").append('<marquee id="msg_tip_marquee_show" style="width: 100%; position:  absolute; top: 100px; right: 0px; color: red; font-size: 18px; z-index: 10000;" scrollamount="3" loop="1">' + decodeURIComponent(command[3]) + '</marquee>');
                var str = '';
                break;
        }
    }
    else
    {
        var msgid = "";
        if (Txt.indexOf('_+_') > -1) {
            var t = Txt.split('_+_');
            msgid = t[0];
            Txt = t[1];
        }
        var msgBlockBt = "";
        if (RoomInfo.msgBlock == "1") {
            if (check_auth('msg_block'))
                msgBlockBt = " <a href='javascript:void(0)' onclick='bt_msgBlock(\"" + msgid + "\")'><img src='images/11.png' style='border:0px;' title='屏蔽消息'></a>";
        }

        //表情不需要审核
        var str = Msg.Txt;
        str = decodeURIComponent(str);
        var res1 = /<img src="\/room\/face\/colorbar\/[a-z]{2,6}.gif">/i.test(str);
        var res2 = /(<img src="\/room\/face\/pic\/[0-9a-z_]{2,11}.gif">){8}/i.test(str);

        var msgAuditBt = "";
        var msgAuditShow = '';
        if (RoomInfo.msgAudit == "1" && (!res1 && !res2)) {
            msgAuditShow = 'style="display:none"';

            if (check_auth('msg_audit')) {
                msgAuditBt = " <a href='javascript:void(0)' onclick='bt_msgAudit(\"" + msgid + "\",this)'><img src='images/22.png' style='border:0px;' title='审核通过'></a>";
                msgAuditShow = "";
            }
            if (User.chatid == My.chatid)
                msgAuditShow = "";
        }
        var grp =' ';//用户组显示
        if(check_auth('room_admin')){
            grp = grouparr[User.color].title + "-" + User.chatid;
        }
        var is_red = check_one_auth(User.color,'room_admin')?'red':'';


        if (toUser.chatid != "ALL") {
            str = '<div style="clear:both; height:0px;"></div><div class="msg" id="' + msgid + '" ' + msgAuditShow + '><div class="msg_content"><div>' + IsPersonal + '<font class="u" style="color:' + aColor[User.sex] + '" >' + User.nick + '</font><div class="msg_head"> <img src="' + grouparr[User.color].ico + '" class="msg_group_ico" title="' + grp + '"></div> <font class="dui">    对</font> <font class="u" style="color:' + aColor[toUser.sex] + '" onclick="ToUser.set(\'' + toUser.chatid + '\',\'' + toUser.nick + '\')">' + toUser.nick + '</font> 说 <font class="date">' + date + '</font></div><div class="layim_chatsay" ><font  style="' + Msg.Style + ';" >' + Txt + msgBlockBt + msgAuditBt + '</font><em class="layim_zero"></em></div></div></div><div style="clear:both; height:0px;"></div>';
        } else {
            str = '<div style="clear:both; height:0px;"></div><div class="msg"  id="' + msgid + '" ' + msgAuditShow + '>' +
                '<div class="msg_content"><div>' + IsPersonal +
                '<font class="date">' + date + '</font>' +
                ' <div class="msg_head"><img src="' + grouparr[User.color].ico + '" class="msg_group_ico"  title="' + grp + '"> </div> ' +
                '<font class="u '+is_red+'" style="color:\' + aColor[User.sex] + \'" >' + User.nick + '</font></div><div class="layim_chatsay" >' +
                '<font  style="' + Msg.Style + ';" >' + Txt + msgBlockBt + msgAuditBt + '</font><em class="layim_zero"></em>' +
                '</div></div></div><div style="clear:both; height:0px;"></div>';
        }
    }
    return str;

}

function ShowGifteffect(gid) {
    var Gift_id = 'G' + Math.round(Math.random()) + Math.round(Math.random());
    var div = CreateElm(false, 'div', false, Gift_id);
    div.style.position = 'absolute';
    div.style.display = "none";
    div.style.top = Math.round(Math.random() * document.documentElement.clientHeight - 50) + 'px';
    div.style.left = Math.round(Math.random() * document.documentElement.clientWidth - 50) + 'px';
    div.innerHTML = '<img src="../gift/img.php?id=' + gid + '" height="80" width="80" />';
    div.style.display = "";
    setTimeout("RemoveElm(false,getId('" + Gift_id + "'))", 5000);
}
var msgBlock = '';
function MsgShow(str, type) {
	var patt = new RegExp(/(\[喊单提醒\])/i);
	if(patt.test(str)) {
		//console.log("喊单提醒");
		document.getElementById("voice").contentWindow.play("喊单提醒");
	}
	//0:box1 show 1:box2 show 2:all show
    var say = null;
    if (fenping)
        type = 0;
    switch (type) {
        case 0:
            $('#MsgBox1').append(str);
            break;
        case 1:
            $('#MsgBox2').append(str);
            break;
        case 2:
            $('#MsgBox2').append(str);
            break;
    }
    if ($('#MsgBox1').find(".msg").length > 100) {
        $('#MsgBox1').find(".msg:first").remove();
    }


    MsgAutoScroll();
}

//获取图片真实宽高
function getImgNaturalDimensions(img, callback) {
    var nWidth, nHeight
    if (img.naturalWidth) { // 现代浏览器
        nWidth = img.naturalWidth
        nHeight = img.naturalHeight
    } else { // IE6/7/8
        var imgae = new Image()
        image.src = img.src
        image.onload = function() {
            callback(image.width, image.height)
        }
    }
    return [nWidth, nHeight]
}

function getImageWidth(url,callback){
    var img = new Image();
    img.src = url;

    // 如果图片被缓存，则直接返回缓存数据
    if(img.complete){
        callback(img.width, img.height);
    }else{
        // 完全加载完毕的事件
        img.onload = function(){
            callback(img.width, img.height);
        }
    }

}





function MsgAutoScroll() {
    if (toggleScroll == true) {
        //getId('MsgBox1').scrollTop = getId('MsgBox1').scrollHeight;
        $('#MsgBox1').animate({scrollTop: $('#MsgBox1')[0].scrollHeight}, 1000);
        if (!fenping)
            $('#MsgBox2').animate({scrollTop: $('#MsgBox2')[0].scrollHeight}, 1000);
        //getId('MsgBox2').scrollTop = getId('MsgBox2').scrollHeight;
    }
}
var blinkerTimer;
var sendMsgTimer;
function MsgAlert(tag)
{
    MsgCAlert();

    if (tag == 0) {
        document.title = '您有新消息！祝你聊得愉快！';
        blinkerTimer = setTimeout('MsgAlert(1)', 1000);
    }
    if (tag == 1) {
        document.title = RoomInfo.defaultTitle;
        blinkerTimer = setTimeout('MsgAlert(0)', 1000);
    }
}
function MsgCAlert()
{
    if (blinkerTimer)
        clearTimeout(blinkerTimer);
    if (sendMsgTimer)
        clearTimeout(sendMsgTimer);
    document.title = RoomInfo.defaultTitle;
}
function sendgift(s, g) {
    //var loadstr='<font color="red">服务器连接失败</font><br>';
    if (s == "ALL" || s == "") {
        alert("没有选择收礼人！");
        return false;
    }
    openWithIframe('赠送礼物', '../sendgift.php?froom=froom&gid=' + g + '&sid=' + s, 300, 200, null, false);
    dragWinx(getId("massage_box"));
}

function saveCode(obj, filename) {
    var winname = window.open("", "", "top=10000,left=10000");
    winname.document.open("text/html", "replace");
    winname.document.writeln(obj);
    winname.document.execCommand("saveas", "", filename + ".html");
    winname.close();
}

function dragWinx(o) {

}
function dragMsgWinx(o) {
    //o.firstChild.onmousedown=function(){return false;};
    o.onmousedown = function(a) {
        var d = document;
        if (!a)
            a = window.event;
        var dy = a.clientY - getId('MsgBox1').offsetHeight;
        var x = getId('MsgBox2').offsetHeight + getId('MsgBox1').offsetHeight;
        if (o.setCapture)
            o.setCapture();
        else if (window.captureEvents)
            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);

        d.onmousemove = function(a) {
            if (!a)
                a = window.event;
            var t = Math.min(Math.max(120, a.clientY - dy), x - 40);
            getId('MsgBox1').style.height = t + 'px';
            getId('MsgBox2').style.height = x - t + 'px';
        };

        d.onmouseup = function() {
            if (o.releaseCapture)
                o.releaseCapture();
            else if (window.captureEvents)
                window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
            d.onmousemove = null;
            d.onmouseup = null;
        };
    };
}
function openWithIframe(tit, url, w, h, str, o) {
    if (url == null)
    {
        $.layer({
            type: 1,
            title: false, //不显示默认标题栏
            shade: [0], //不显示遮罩
            area: ['600px', '360px'],
            page: {html: '<img src="http://static.oschina.net/uploads/space/2014/0516/012728_nAh8_1168184.jpg" alt="layer">'}
        });
    }
    else
    {
        $.layer({
            type: 2,
            title: tit != "" ? tit : false,
            maxmin: false,
            shadeClose: true, //开启点击遮罩关闭层
            area: [w + 'px', h + 'px'],
            offset: ['100px', ''],
            iframe: {src: url}
        });
    }
}

function closeWithIframe() {
    layer.close();
}

//魔法表情
function online(rst)
{

    var xmlhttp = XHConn();
    var request_url = "../ajax.php?act=online&rst=" + rst + "&num=" + getId('OnlineUserNum').innerHTML + "&" + Math.random() * 10000;

    try {
        xmlhttp.open('GET', request_url, true);
        xmlhttp.send(null);
        xmlhttp.onreadystatechange = function()
        {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
            {
                var re = eval("(" + xmlhttp.responseText + ")");
                if (re.state == "logout")
                {
                    alert('你还没有登陆！');
                    location.href = '../index.php'
                }
                else if (re.state == 'ologin')
                {
                    var str = '<div><img src="images/true.png" width="16" height="16"  style="vertical-align:text-bottom" /> ' + Datetime(0) + ' <br /> &nbsp;&nbsp;&nbsp;帐号其他地方登录或网络异常！统一帐号不能两个地方（浏览器登录）！ <a href="javascript:location.reload()" style="color:#0033FF;cursor:pointer">点击重新连接</a> </div>';
                    //MsgShow(str, 1);
                }
            }
            return true;
        }
    }
    catch (e) {
        return true;
    }
}
function ColorNick(id, i) {
    return;
    if (i >= 9)
        i = 0;
    var col = ["white", "coral", "orange", "red", "greenyellow", "lime", "turquoise", "coral", "blueviolet", "violet"];
    document.getElementById(id).style.color = col[i++];
    setTimeout("ColorNick('" + id + "'," + i + ")", 100);
}
function playSound(file) {
    getId('MsgSound').innerHTML = '<audio  src="sounds/' + file + '" loop="0" autostart="true" hidden="true"></audio>';
}
function openWin(type, title, content, w, h) {
    var winWidth =    $(window).width()-100;
    var winHeight=    $(window).height()-100;
    if(w >winWidth ){
        w =winWidth;
    }
    if(h >winHeight ){
        h =winHeight;
    }

    if( w=='100%'&& h=='100%' ){
        var width =winWidth+'px';
        var height =winHeight+'px';
    }else{
        var width =w + 'px';
        var height = h + 'px';
    }

    layer.closeAll('iframe');
    layer.open({
        type: type,
        title: title,
        bgcolor: '',
        shadeClose: true,
        shade: false,
        area: [width,height],
        content: content, //iframe的url
        zIndex: 9999999,
    });
}

function openApp(obj) {
    layer.closeAll('iframe');
    if (obj.target == "NewWin") {
        window.open(obj.url);
    }
    else if (obj.target == "POPWin") {
        layer.open({
            type: 2,
            title: obj.title,
            shadeClose: true,
            shade: false,
            area: [obj.w + 'px', obj.h + 'px'],
            content: obj.url //iframe的url
        });
    }
    else if (obj.target == "QPWin") {
        layer.open({
            type: 2,
            shade: false,
            title: false, //不显示标题
            content: obj.url, //捕获的元素
            area: [obj.w + 'px', obj.h + 'px']
        });
    }

}
function loginTip() {
    //$('#OnLine_MV').html('直播体验结束，请登录！');
    //openWin(2, false, 'minilogin.php', 390, 310);
    openWin(2, false, 'news/alert_login.php', 1010, 610);

}
function app_sendmsg(msg) {	
    var msgid = randStr() + randStr();

    if(msg == '含敏感关键字，内容被屏蔽'){
        layer.msg('含敏感关键字！', {shift: 6});
        return false;
    }

    // var str = 'SendMsg=M=ALL|false|color:#000|' + encodeURIComponent(msg.str_replace());

    ws.send('{"type":"say","touser":"'+'ALL'+'","IsPersonal":"'+false+'","Style":"'+'color:#000'+'","Msg":"'+ encodeURIComponent(msg.str_replace()) +'","qx":"'+My.qx+'"}');

    // socket.emit('message', str);


    PutMessage(My.rid, My.chatid, 'ALL', My.nick, 'ALL', 'false', '', msg.str_replace(), msgid)
}
function check_auth(auth) {
    var auth_rules = grouparr[My.color].rules;
    if (auth_rules.indexOf(auth) > -1)
        return true;
    else
        false;
}
function check_one_auth(color,auth) {
    var auth_rules = grouparr[color].rules;
    if (auth_rules.indexOf(auth) > -1)
        return true;
    else
        false;
}
function remove_auth(auth) {
    grouparr[My.color].rules = grouparr[My.color].rules.replace(auth, "");
}
function BrdBlur(id) {

    var e = getEvent();
    var act = document.activeElement ? document.activeElement : e.explicitOriginalTarget
    var src = e.srcElement ? e.srcElement : e.target
    if (!CommObjectCheck(act, src)) {
        getId(id).style.display = 'none';
    }
}

function HideMenu()
{
    var elementTable = ["ColorTable", "Send_key_option", "FontBar"];
    for (var i = 0; i < elementTable.length; i++)
        getId(elementTable[i]).style.display = 'none'
}
//全局事件绑定
//window.onblur =function(){
//    if(!isIE){
//        HideMenu();
//    }
//}; 
function getEvent() //同时兼容ie和ff event
{
    if (document.all)
        return window.event;
    func = getEvent.caller;
    while (func != null) {
        var arg0 = func.arguments[0];
        if (arg0)
        {
            if ((arg0.constructor == Event || arg0.constructor == MouseEvent) || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation))
            {
                return arg0;
            }
        }
        func = func.caller;
    }
    return null;
}
function MsgKeyDown()
{

}

function randStr() {
    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
//初始化表情包和彩条
function sendCaitiao(tag) {
    var ct = [];
    ct['dyg'] = '<img src="/room/face/colorbar/dyg.gif">';
    ct['zyg'] = '<img src="/room/face/colorbar/zyg.gif">';
    ct['gl'] = '<img src="/room/face/pic/s1.gif"><img src="/room/face/pic/s1.gif"><img src="/room/face/pic/s6.gif"><img src="/room/face/pic/s6.gif"><img src="/room/face/pic/geili_thumb.gif"><img src="/room/face/pic/geili_thumb.gif"><img src="/room/face/pic/s0.gif"><img src="/room/face/pic/s0.gif">';
    ct['zs'] = '<img src="/room/face/colorbar/zs.gif">';
    ct['xh'] = '<img src="/room/face/colorbar/xh.gif">';
    app_sendmsg(ct[tag]);
}
function showFacePanel(e, toinput) {
    var offset = $(e).offset();

    var t = offset.top;
    var l = offset.left;
    $('#face').css({"top": t - $('#face').outerHeight(), "left": l});
    $('#face').show();
    $('#face').attr("toinput", toinput);
}
function  initFaceColobar() {

    $.get("face/pic/face.html", function(data) {
        $('#face').html(data);
        $('#facenav li').on('click', function() {
            var rel = $(this).attr('rel');
            $('#face dl').hide();
            $('#f_' + rel).show();
            $(this).siblings().removeClass('f_cur');
            $(this).addClass('f_cur');

        });
    }).success(function() {
        $(document).bind('mouseup', function(e) {
            if ($(e.target).attr('isface') != '1' && $(e.target).attr('isface') != '2')
            {
                $('#face').hide();
                //$(document).unbind('mouseup');
            }
            else if ($(e.target).attr('isface') == '1')
            {
                var toinput = $('#face').attr("toinput");
                if($(e.target).attr("src")!= undefined){
                    $(toinput).append('<img src="' + $(e.target).attr('src') + '" onresizestart="return false" contenteditable="false">');
                }
            }
        });


    });

    $.get("face/colorbar/colorbar.html", function(data) {
        $('#caitiao').html(data);
        //彩条
        $('#bt_caitiao').on('click', function() {
            var offset = $('#bt_caitiao').offset();
            var t = offset.top;
            var l = offset.left;
            $('#caitiao').css({"top": t - $('#caitiao').outerHeight(), "left": l});

            $('#caitiao').show();

        });
        $('#caitiaonav li').on('click', function() {

            var rel = $(this).attr('rel');
            $('#caitiao dl').hide();
            $('#c_' + rel).show();
            $(this).siblings().removeClass('f_cur');
            $(this).addClass('f_cur');
        });
        $(document).bind('mouseup', function(e) {
            if ($(e.target).attr('isnav') != '1')
            {
                $('#caitiao').hide();
            }
        });
    });
}
function showBgList() {
    $('.layui-layer-page .layui-layer-content').html('');
    var bg_img_list = '<img src="'+ bg_img + '" class="bg_list" onclick="changeBg(\''+ bg_img + '\')">';
    for(var i=1;i<=23;i++) {
		bg_img_list = bg_img_list+'<img src="skins/bg/w'+ i + 'x.jpg" class="bg_list" onclick="changeBg(\'skins/bg/w'+ i + '.jpg\')">'; 
    }
    bg_img_list = "<div style='padding: 5px;'>" + bg_img_list + "</div>";
    //页面层
    layer.open({
        type: 1,
        title: false,
        closeBtn: true,
        area: ['810px', '316px'],
        skin: '#CCC', //没有背景色
        shadeClose: true,
        content: bg_img_list
    });   
}


function showBgList1() {
    //$('.layui-layer-page .layui-layer-content').html('');
    var bg_img_list = '<div class="outlist">'+$('.mylist').html()+'</div>';
     bg_img_list += '<script charset="utf-8" src="http://wpa.b.qq.com/cgi/wpa.php"></script>';

    //页面层
    layer.open({
        type: 1,
        title: false,
        closeBtn: true,
        area: ['810px', '500px'],
        skin: '#CCC', //没有背景色
        shadeClose: true,
        content: bg_img_list,
        success: function(layero, index){

            //点击在线客服触发
            var a_obj = $('.outlist a');
            var data = [];
            for(var i=0;i<a_obj.length;i++){
                if(i == 0){
                    var visit = $('.outlist a:eq('+i+')').attr('qq');
                }
                var qq = $('.outlist a:eq('+i+')').attr('qq');
                var pre = $('.outlist a:eq('+i+')').attr('pre');

                data[i] = {aty: '0', a: '0', nameAccount: qq, selector: pre+qq}
            }
            BizQQWPA.addCustom(data);
            //访客功能
            BizQQWPA.visitor({
                nameAccount: visit
            });
        }
    });
}
function changeBg(src){
    $('body').attr('style', 'background: #408080 url(' + src + ') repeat scroll 0 0');
    $.cookie('bg_img',src, {expires: 365, path: '/'});
}

/**
 * 时间戳转换日期
 * @param <int> unixTime    待时间戳(秒)
 * @param <bool> isFull    返回完整时间(Y-m-d 或者 Y-m-d H:i:s)
 * @param <int>  timeZone   时区
 */
function UnixToDate(unixTime, isFull, timeZone) {
    if (typeof (timeZone) == 'number')
    {
        unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
    }
    var time = new Date(unixTime * 1000);
    var ymdhis = "";
    ymdhis += time.getUTCFullYear() + "-";
    ymdhis += (time.getUTCMonth()+1) + "-";
    ymdhis += time.getUTCDate();
    if (isFull === true)
    {
        ymdhis += " " + time.getUTCHours() + ":";
        ymdhis += time.getUTCMinutes() + ":";
        ymdhis += time.getUTCSeconds();
    }
    return ymdhis;
}

//处理黑板报的显示状态
function setBlackSate(){
    var start_time = $('.line_ad').attr('start_time');
    var end_time = $('.line_ad').attr('end_time');
    var now = Date.parse(new Date())/1000;

    //console.log('开始'+UnixToDate(start_time,true,8));
    //console.log('结束'+UnixToDate(end_time,true,8));
    //console.log('现在'+UnixToDate(now,true,8));

    if(start_time<now && end_time>now ){
        $('.line_ad').show();
    }else {
        $('.line_ad').hide();
    }
}

//处理音乐报的显示状态
function setMusicSate(){
    var start_time = $('#audio1').attr('start_time');
    var end_time = $('#audio1').attr('end_time');
    var now = Date.parse(new Date())/1000;

    //console.log('开始'+UnixToDate(start_time,true,8));
    //console.log('结束'+UnixToDate(end_time,true,8));
    //console.log('现在'+UnixToDate(now,true,8));

    if(start_time<now && end_time>now ){
        console.log('定时开');
        bf(1);
    }else {
        console.log('定时关');
        bf(0);
    }

}

function bf(isplay){
    var audio = document.getElementById('audio1');
    if(audio!==null){
        //检测播放是否已暂停.audio.paused 在播放器播放时返回false.
        if(isplay){
            console.log('播放');
            audio.play();//audio.play();// 这个就是播放
        }else{
            console.log('暂停');
            audio.pause();// 这个就是暂停
        }
    }
}


function dfavatar(i){
    var u ="/face/rebot/"+Math.floor(Math.random()*(40-2+1)+2)+".png";
    $(i).prop('src',u);
}
function dfavatarNum(i){

    var num = Math.floor(Math.random()*(40-2+1)+2);
    return "/face/rebot/"+(num>9?num:('0'+num))+".png";

}

$(function(){
    $(document).on('click',".layim_chatsay img", function() {
        var wh = getImgNaturalDimensions(this);
        openWin(2,false,$(this).attr('src'),wh[0],wh[1])
    });
})

/**/
function firstWin(){
    // openWin(1, false, $("#tip_login_win").html(), 800, 350);
    //openWin(2, false, 'http://www.17sucai.com/preview/1/2016-10-31/yh/index.html', '100%', '100%');
    $('#alertad img').each(function(i){
        var wh = getImgNaturalDimensions(this);
        openWin(1, false, $("#tip_login_win").html(), wh[0],wh[1]);
    });
}


//获取参数数组 tonyjiang
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

//原参数添加 tonyjiang
function jumpUrl(url){
    if(location.search == ''){
        var str='?1=1';
    }else {
        var str = location.search;
    }
    return url+str; //获取url中"?"符后的字串
}

var t = 0;
function sendmsg(str){
    // socket.emit('message', str);
    ws.send(str);



}

//弹出图片弹窗
function alertImg(url){
    getImageWidth(url,function(w,h){
        openWin(2,false,url,w+20,h+20);
    });
}

/*
** randomWord 产生任意长度随机字母数字组合
** randomFlag-是否任意长度 min-任意长度最小位[固定位数] max-任意长度最大位
** xuanfeng 2014-08-28
*/

function randomWord(randomFlag, min, max){
    var str = "",
        range = min,
        // arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
    arr = ['要','擒','牛','股','短','线','王','波','段','龙','白','马','黑','马','荷','塘','月','色','爱','涨','停','带','刺','的','玫','瑰','股','市','老','涨','金','手','指','勿','忘','我','热','情','沙','漠','老','司','机','王','者','荣','耀','老','八','九','哥','牵','牛','花','鱼','遇','海','安','谧','九','黎','知','足','猛','爷','执','着','小','月','山','人','与','庄','共','舞','慧','眼','识','股','心','中','有','K','线','手','握','金','股','开','门','红','红','光','满','天','股','博'];

    // 随机产生
    if(randomFlag){
        range = Math.round(Math.random() * (max-min)) + min;
    }
    for(var i=0; i<range; i++){
        pos = Math.round(Math.random() * (arr.length-1));
        str += arr[pos];
    }
    return str;
}
/*
** randomWord 产生任意长度随机字母数字组合
** randomFlag-是否任意长度 min-任意长度最小位[固定位数] max-任意长度最大位
** xuanfeng 2014-08-28
*/

function randomCnWord(randomFlag, min, max){
    var str = "",
        range = min,
        arr = ['我要擒牛股','短线王','波段龙','白马','黑马','荷塘月色','爱涨停','带刺的玫瑰','股市老涨','金手指','勿忘我','热情沙漠','老司机','王者荣耀','老八','九哥','牵牛花','鱼遇海','安谧','九黎','知足','猛爷','执着','小月','山人','与庄共舞','慧眼识股','心中有K线','手握金股','开门红','红光满天','股博'];

    // 随机产生
    var rand_num = rnd(min, max);
console.log(rand_num);
    var str = arr[rand_num];
    return str;
}

//取得一个区间的随机整数
function rnd(n, m){
    var random = Math.floor(Math.random()*(m-n+1)+n);
    return random;
}


//展示二维码
function showCode(cost, id) {
    $('.gift_ewm').show();
    //var loadstr='<font color="red">服务器连接失败</font><br>';
}

//发送礼物
function sendgiftMsg(data) {

    if(My.diamond < data.num*data.gift_money){
        alert('您的钻石余额不足,请充值.');return false;
    }

    My.diamond = My.diamond - data.num*data.gift_money;
    //提交log,更新数据
    postGif(data);

    var data_str = JSON.stringify(data);

    // var str = 'SendGifMsg=M=' + ToUser.id + '|' + getId('Personal').value + '|' + data_str;

    // ws.send('{"type":"SendGifMsg","touser":"'+ToUser.id+'","IsPersonal":"'+getId('Personal').value+'","data_str":"'+data_str+'"}');

    ws.send('{"type":"SendGifMsg","touser":"'+ToUser.id+'","IsPersonal":"'+getId('Personal').value+'","data_str":'+data_str+'}');

    // socket.emit('message', str);

}

//提交log,更新数据
function postGif(data){
    var request_url = '../ajax.php?act=postGif';
    var diamond = data.num*data.gift_money;
    var postdata = '&diamond=' + diamond + '&nick=' + data.nick + '&num=' + data.num + '&gift_id=' + data.gift_id + '&gift_name=' + data.gift_name + '&' + Math.random() * 10000;
    $.ajax({type: 'POST', url: request_url, data: postdata});
}

//跑马灯
function rideHorse(str){
    if($('#msg_tip_marquee_show').html() != undefined) {
        $('#msg_tip_marquee_show').remove();
    }
    $("body").append('<marquee id="msg_tip_marquee_show" style="width: 100%; position:  absolute; top: 100px; right: 0px; color: red; font-size: 50px; z-index: 10000;" scrollamount="3" loop="1">' + decodeURIComponent(str) + '</marquee>');
    var str = '';
}
